﻿using Estsh.Core.Controllers;
using Estsh.Core.Model.Extend.Models;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Wms.IServices;
using Microsoft.AspNetCore.Mvc;

namespace Estsh.Core.Web.Plugin.Wms.Areas.wms.Controllers.OutStock
{
    [Route("wms/[controller]")]
    [ApiController]
    public class OutSourceShippingController: WmsBaseController
    {
        public IOutSourceShippingService service;

        public OutSourceShippingController(IOutSourceShippingService _service)
        {
            service= _service;
        }

        /// <summary>
        /// 获取委外发运单
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("GetOutSource")]
        public IActionResult GetOutSource(Newtonsoft.Json.Linq.JObject jobj)
        {
            string orderNo = jobj["orderNo"].ToString().Trim();
            WmsResponseResult result = new WmsResponseResult();
            try
            {
                List<WmsOutstock_Extend> wmsOutstocks = service.GetOutStocks(orderNo);
                result.Data = wmsOutstocks;
                result.Success = true;
            }
            catch (Exception ex) 
            { 
                result.Msg= ex.Message;
            }
            return Json(result);
        }

        /// <summary>
        /// 获取委外发运单明细
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("GetOutStockDetail")]
        public IActionResult GetOutStockDetail(Newtonsoft.Json.Linq.JObject jobj)
        {
            string orderNo = jobj["orderNo"].ToString().Trim();
            WmsResponseResult result= new WmsResponseResult();
            try
            {
                List<WmsOutstockDetail> outstockDetails=service.GetOutstockDetails(orderNo);
                result.Data = outstockDetails;
                result.Success = true;
            }
            catch (Exception ex)
            {
                result.Msg= ex.Message;
            }
            return Json(result);
        }
    }
}
